package com.share.framework.starter.shenyu;

import com.share.framework.common.config.shenyu.other.ShenyuClientRegisterRepository;
import com.share.framework.common.config.shenyu.properties.PropertiesConfig;
import com.share.framework.common.config.shenyu.properties.ShenyuClientConfig;
import com.share.framework.init.shenyu.ContextRegisterListener;
import com.share.framework.init.shenyu.SpringMvcClientBeanPostProcessor;
import com.share.framework.starter.properties.shenyu.ShenyuClientCommonBeanConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@ImportAutoConfiguration({ShenyuClientCommonBeanConfiguration.class})
public class ShenyuSpringMvcClientConfiguration {
    private static String TYPE = "http";

    public ShenyuSpringMvcClientConfiguration() {
    }

    @Bean
    public SpringMvcClientBeanPostProcessor springHttpClientBeanPostProcessor(ShenyuClientConfig clientConfig, ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
        return new SpringMvcClientBeanPostProcessor((PropertiesConfig) clientConfig.getClient().get(TYPE), shenyuClientRegisterRepository);
    }

    @Bean
    public ContextRegisterListener contextRegisterListener(ShenyuClientConfig clientConfig) {
        return new ContextRegisterListener((PropertiesConfig) clientConfig.getClient().get(TYPE));
    }
}